#!/bin/sh

APP_CONFIG_FILE=/mnt/nand1-2/update/UpdateFile/app.config

WAP_HW_INFO="/mnt/nand1-2/update/Software.info"
DEV_NETCONFIG="/mnt/nand1-1/wifi/network_config"

if [ ! -f $APP_CONFIG_FILE ]; then
        echo "Can't find $APP_CONFIG_FILE This Update zip is Bad"
        exit 1
fi

if [ ! -f $WAP_HW_INFO ]; then
        echo "Can't find $WAP_HW_INFO This Update zip is Bad"
        #exit 1
fi

echo "get app.config ..."

#get HW_Version
APP_HW_V=`awk '{if ($1=="HW_Version") {print $2}}' $APP_CONFIG_FILE`

#get SW_Version
APP_SW_V=`awk '{if ($1=="SW_Version") {print $2}}' $APP_CONFIG_FILE`

#get dev mac addr
DEV_MAC=`awk '{if ($1=="DEV_MAC") {print $2}}' $APP_CONFIG_FILE`

#get dev mac addr
DEV_MAC1=`awk '{if ($1=="AP_SSID") {print $2}}' $DEV_NETCONFIG`
echo "$APP_HW_V , $APP_SW_V , $APP_OLD_NAME , $APP_NEW_NAME"

#get device HW_Version
WAP_HW_V=`awk '{if ($1=="HW_Version") {print $2}}' $WAP_HW_INFO`

killall monitoring.sh
killall sd700
killall netrelink.sh 
killall axel 
echo -n V > /dev/watchdog

cd /mnt/nand1-2/update/UpdateFile

if [ "$APP_HW_V" == "$WAP_HW_V" ];then		
	echo "This WAP Hardware Versions is $WAP_HW_V"
	echo "This update MAC :$DEV_MAC mac1 $DEV_MAC1"
	
	if [ "$DEV_MAC" == "ALL" ];then
		if [ ! -d "/mnt/nand1-2/res/sys/" ];then
			#mkdir /mnt/nand1-2/res/sys/
		fi
		cp sd700 /mnt/nand1-1/
		#cp sd700_bat /mnt/nand1-1/
		#cp network_config_ap /mnt/nand1-1/wifi
		#cp axel /mnt/nand1-1/
		#cp wifi.sh /mnt/nand1-1/wifi
		cp relink.sh /mnt/nand1-1/wifi
		#cp update.jpg /mnt/nand1-2/res/sys/
		#cp sysinfo.jpg /mnt/nand1-2/res/sys/
		#cp loadinfo.jpg /mnt/nand1-2/res/sys/
		#cp nonenet.jpg /mnt/nand1-2/res/sys/
		#cp netbreak.jpg /mnt/nand1-2/res/sys/
		cp Price.jpg /mnt/nand1-1/res/sys/
		#cp relink.sh /mnt/nand1-1/wifi/
		echo "update succeed ^_^"	
		exit 0
	fi
	if [ "$DEV_MAC" == "$DEV_MAC1" ];then
		cp sd700 /mnt/nand1-1/
		echo "update succeed ^_^"	
		
	fi
	exit 0
else
	echo "This HW_Version is UNMatch"
fi

exit 0
